package com.yznote.compileserver.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * @author : xiaozhoutongxue
 * @date : 2022/10/12 20:56
 * 统一返回结果
 */
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    private T data;
    private Integer code;
    private String msg;

    public static <T> Result<T> build(T data, Integer code, String msg) {
        Result<T> result = new Result<>(data, code, msg);
        return result;
    }

    public static <T> Result<T> sussess(T data, String msg) {
        Result<T> result = new Result<>(data, 200, msg);
        return result;
    }

    public static <T> Result<T> fail(String msg) {
        Result<T> result = new Result<>(null, 500, msg);
        return result;
    }
}
